package SV_PERMS_WIDE;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.util.Set;

public class Vulnerable_02 {
    public static class FilePosix {
        public static void test() throws Exception {
            Path path = Paths.get("/home/ubuntu/test");
            String s = "rwxrwxr-x";
            Set<PosixFilePermission> perms = PosixFilePermissions.fromString(s); // matched to '****w*rwx' -> Defect found!
            FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);
            Files.createDirectory(path, attr);
        }
    }
}
